#include "DarkGDK.h"
// *********************************************************
// game_interface controls the gui that the player interacts
// with. The player can create buildings or military units
// from within the gui. 
// *********************************************************


/**
*game_interface controls the gui that the player interacts with. The player can create buildings or military units from within the gui. 
*/
class game_interface {

public:
    int display_height; //to determine the position of the gui

	void create_interface( void ) {
		/**
		* Creates the interface of the game. 
		*/

		display_height = 600; //default resolution is 800x600

        dbLoadImage("pointer_sprite.png", 1); //clear image used to check for collision
		dbLoadImage("gui.png", 2); //gui background image

		load_images(); //load the button images
		//create_radar();
	}

		/**
		* Loops the interface controls. Checks if buttons are clicked, if so, return 
		* the buttons to Main to tell what objects to build. 
		*/
	int interface_loop(int civilization_number) {
		dbPasteImage(2, 0, display_height-211, 1); // show the gui image 
	
		dbSprite(100, dbMouseX(), dbMouseY(), 1); // move the pointer sprite to where the mouse is

		create_buttons(civilization_number); //create the buttons and make them hoverable

		// return the button codes if they are clicked
		if(check_click(31)) return 32; //military building
		if(check_click(32)) return 31; //oil derek

		if(check_click(34)) return 34; //tank 1
		if(check_click(36)) return 36; //tank 2

		if(check_click(50)) return 50; //town center
		if(check_click(52)) return 52; //mine

		if(check_click(54)) return 54; //dragon 1
		if(check_click(56)) return 56; //dragon 2

		// if no buttons are clicked return 0
		return 0;
	}

	// method to check if the button-sprite has collided w/ selector-sprite
	bool check_click ( int sprite ) {
		/**
		* method to check if the button-sprite has collided w/ selector-sprite
		*/
		if(dbMouseClick() == 1 ) {
			return dbSpriteCollision(100, sprite); 
		}
		return 0; //if mouse has not been clicked return 0
	}

	// create hover and click effects
	// sprite is sprite number
	// hover is hovered image number
	// replace current image with hover image when hovered
	void hover(int sprite, int hover) {
		/**
		*create hover and click effects replace current image with hover image when hovered
		*@param sprite is sprite number 
		*@param hover is hovered image number 
		*/
		if(dbSpriteCollision(100, sprite))
			dbSprite(sprite, dbSpriteX(sprite), dbSpriteY(sprite), hover);
	}

	// create the radar
	void create_radar ( void ) {
		/**
		*creates the radar
		*/

		/*dbMakeCamera(2);
		dbPositionCamera ( 2, 10, 50, 10);
		dbPointCamera (2, 0, 0, 0 );
		dbSetCameraView (2, 20, display_height-165, 190, 590 );*/
		
		//dbMakeCamera(2);
		//dbPositionCamera ( 2, 10, 50, 10);
		//dbPointCamera (2, 30, 0, 30 );
		//dbSetCameraView (1, 20, display_height-165, 190, 590 );
		//dbSetCurrentCamera (1);

	}

	// 
	// load the images for BOTH CIVILIZATIONS for the gui icons
	void load_images(void) {
		/**
		*loads the images for BOTH CIVILIZATIONS for the gui icons
		*/
	
		//for metal
		dbLoadImage("NEW Military Base Button PNG.png", 30);
		dbLoadImage("NEW Military Base Pressed Button PNG.png", 31);

		dbLoadImage("NEW Oil Rig Button PNG.png", 32);
		dbLoadImage("NEW Oil Rig Pressed Button PNG.png", 33);

		dbLoadImage("NEW Camo Tank Button PNG.png", 34);
		dbLoadImage("NEW Camo Tank Pressed Button PNG.png", 35);

		dbLoadImage("NEW Metal Tank Button PNG.png",36 );
		dbLoadImage("NEW Metal Tank Pressed Button PNG.png",37 );

		//for magic
		dbLoadImage("NEW Town Center Button PNG.png", 38);
		dbLoadImage("NEW Town Center Pressed Button PNG.png", 39);

		dbLoadImage("NEW Mine Button PNG.png",40 );
		dbLoadImage("NEW Mine Pressed Button PNG.png",41 );

		dbLoadImage("NEW Red Dragon Button PNG.png", 42);
		dbLoadImage("NEW Red Dragon Pressed Button PNG.png", 43);

		dbLoadImage("NEW Gold Dragon Button PNG.png",44 );
		dbLoadImage("NEW Gold Dragon Pressed Button PNG.png",45 );

	}

	// create the buttons for the civilization depending on the civilization number
	void create_buttons(int civilization_number) {	
		/**
		*create the buttons for the civilization depending on the civilization number
		*/
		
		if(civilization_number == 1) {
			dbSprite(31, 280, 490, 30); // top left metal
			hover(30, 31);

			dbSprite(32, 380, 490, 32); // top right metal
			hover(32, 33);

			dbSprite(34, 580, 490, 34); // bottom left metal
			hover(34, 35);

			dbSprite(36, 675, 490, 36); // bottom right metal
			hover(36, 37);
		}

		else if(civilization_number == 2) {
			dbSprite(38, 280, 490, 38); // top left metal
			hover(38, 39);

			dbSprite(40, 380, 490, 40); // top right metal
			hover(40, 41);

			dbSprite(42, 580, 490, 42); // bottom left metal
			hover(42, 43);

			dbSprite(44, 675, 490, 44); // bottom right metal
			hover(44, 45);	
		}
	}
};